package com.aldobucchi.x.Object
{
	public class ObjectUtil
	{







		/**
		 * 
		 * Will iterate the object with a for loop and copy visible members
		 * 
		 * @param obj
		 * @return 
		 * 
		 */
		public static function makeShallowCopy( obj:Object ):Object
		{
		
			var copy:Object = {};

			for ( var name:* in obj )
				copy[ name ] = obj[ name ];

			return copy;			
		
		
		}



		/**
		 * 
		 * Iterates using for( ) and copies key-values from source to target
		 * 
		 * @param source
		 * @param target
		 * 
		 */		
		public static function shallowMerge( source:Object, target:Object ):void
		{
			
			for ( var name:* in source )
			{
				target[ name ] = source[ name ];					
			}
		
		}
		
		
		
		
		
		
		/**
		 * 
		 * 
		 * 
		 * @param obj1
		 * @param obj2
		 * @param strict
		 * @return 
		 * 
		 */		
		public static function shallowCompare( obj1:Object, obj2:Object, strict:Boolean = false ):Boolean
		{
		
			if ( obj1 === obj2 )
				return true;
			
			
			if ( (obj1 == null) && (obj2==null) )
				return true;
				
				
			if ( obj1 == null )
				return false;
				
				
			if ( obj2 == null )
				return false;
		
		
			var count:int = 0, name:*;
			
			if ( strict )
			{
				for (  name in obj1 )
					if ( obj1[ name ] === obj2[ name ] )
						count ++;
					else
						return false;
			}
			else
			{
				for (  name in obj1 )
					if ( obj1[ name ] == obj2[ name ] )
						count ++;
					else
						return false;
			}
			
			
			for ( name in obj2 )
				count--;
				
			return ( count == 0 );
		
		}
		
		
		
		
		
		


	}

}











